package com.appwoo.txtws.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.adapter.ListViewCreator;
import com.appwoo.txtws.adapter.Page;
import com.appwoo.txtws.adapter.SimpleListAdapter;
import com.appwoo.txtws.app.App;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.CallsBean;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.SearchRecordService;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.xmlpull.v1.XmlPullParserException;

public class FindCallRecord extends AppActivity
  implements AdapterView.OnItemClickListener
{
  private static final String TAG = "FindCallRecord";
  private static CallsBean asi;
  private String TIMES;
  private SimpleListAdapter<CallsBean> adapter;
  private StateBean bean;
  private boolean blDataTask;
  private Button cancle;
  public ArrayList<CallsBean> clist;
  public ArrayList<CallsBean> cmmaplist;
  private Button delete;
  private CallsBean delete_calls;
  private String delete_calls_info;
  private int dialgoWidth;
  private int dialgoheight;
  private ArrayList<CallsBean> events;
  private int flag = 0;
  private int flagid;
  private boolean isFoot;
  private ListView list;
  private PageListView lvList;
  private HashMap<String, Integer> maplist;
  private ImageView moreset;
  private HashMap<String, Integer> new_maplist;
  private ArrayList<CallsBean> newlist;
  private Page<CallsBean> page = new Page();
  private String per_num;
  private PopupWindow popupWindow;
  private ViewGroup popupWindow_view;
  private PopupWindow popupWindows;
  private RelativeLayout rl;
  private int screenHeight;
  private int screenWidth;
  private boolean sel_all = false;
  private Integer times;

  private void addCall()
  {
    for (int i = 0; ; i++)
    {
      if (i >= this.page.getEntries().size())
        return;
      this.newlist.add((CallsBean)this.page.getEntries().get(i));
      this.maplist.put(String.valueOf(((CallsBean)this.page.getEntries().get(i)).getId()), Integer.valueOf(((CallsBean)this.page.getEntries().get(i)).getId()));
    }
  }

  private void getPopupWindow(View paramView)
  {
    if ((this.popupWindow != null) && (this.popupWindow.isShowing()))
    {
      this.popupWindow.dismiss();
      this.popupWindow = null;
      return;
    }
    initPopuptWindow(paramView);
  }

  private void initActionBar()
  {
    setBarTitle(getResources().getString(2131428110));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        FindCallRecord.this.finish();
      }
    });
    this.moreset = ((ImageView)findViewById(2131492864).findViewById(2131493280));
    this.moreset.setImageResource(2130837828);
    LinearLayout.LayoutParams localLayoutParams = (LinearLayout.LayoutParams)this.moreset.getLayoutParams();
    localLayoutParams.height = 45;
    localLayoutParams.width = 45;
    this.moreset.setLayoutParams(localLayoutParams);
    setBarHomeOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        FindCallRecord.this.getPopupWindow(paramAnonymousView);
      }
    });
  }

  private void initView()
  {
    new ArrayList();
    this.new_maplist = new HashMap();
    this.newlist = new ArrayList();
    this.maplist = new HashMap();
    this.lvList = ((PageListView)findViewById(2131493065));
    this.rl = ((RelativeLayout)findViewById(2131493019));
    this.cancle = ((Button)findViewById(2131493023));
    this.cancle.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        FindCallRecord.this.flag = 0;
        FindCallRecord.this.sel_all = false;
        FindCallRecord.this.rl.setVisibility(8);
        FindCallRecord.this.setEvent(0);
      }
    });
    this.delete = ((Button)findViewById(2131493024));
    this.delete.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (FindCallRecord.this.maplist.size() > 0)
        {
          String str = "将删除当前所选的 " + FindCallRecord.this.maplist.size() + " 项记录";
          FindCallRecord.this.DeleteRecordDialog(FindCallRecord.this, str);
          return;
        }
        FindCallRecord.this.alertMessage(FindCallRecord.this.getString(2131428118));
      }
    });
    this.adapter = new SimpleListAdapter(this.page.getEntries(), new ListViewCreator()
    {
      public View createView(final CallsBean paramAnonymousCallsBean, View paramAnonymousView, int paramAnonymousInt)
      {
        if (paramAnonymousView == null)
          paramAnonymousView = App.getLayoutInflater().inflate(2130903179, null);
        TextView localTextView1 = (TextView)paramAnonymousView.findViewById(2131493008);
        TextView localTextView2 = (TextView)paramAnonymousView.findViewById(2131493010);
        TextView localTextView3 = (TextView)paramAnonymousView.findViewById(2131493009);
        final CheckBox localCheckBox = (CheckBox)paramAnonymousView.findViewById(2131493011);
        label103: int i;
        String str2;
        if (FindCallRecord.this.flag == 1)
        {
          localCheckBox.setVisibility(0);
          FindCallRecord.this.flagid = paramAnonymousCallsBean.getCid();
          if (FindCallRecord.this.flagid != 1)
            break label334;
          localCheckBox.setChecked(true);
          localCheckBox.setOnClickListener(new View.OnClickListener()
          {
            public void onClick(View paramAnonymous2View)
            {
              if (localCheckBox.isChecked())
              {
                paramAnonymousCallsBean.setCid(1);
                FindCallRecord.this.newlist.add(paramAnonymousCallsBean);
                FindCallRecord.asi = paramAnonymousCallsBean;
                FindCallRecord.this.maplist.put(String.valueOf(paramAnonymousCallsBean.getId()), Integer.valueOf(FindCallRecord.asi.getId()));
              }
              do
              {
                return;
                paramAnonymousCallsBean.setCid(0);
                FindCallRecord.asi = paramAnonymousCallsBean;
                if (FindCallRecord.this.maplist.containsKey(paramAnonymousCallsBean.getId()))
                {
                  FindCallRecord.this.newlist.remove(paramAnonymousCallsBean);
                  FindCallRecord.this.maplist.remove(paramAnonymousCallsBean.getId());
                }
              }
              while (!FindCallRecord.this.newlist.contains(paramAnonymousCallsBean));
              FindCallRecord.this.newlist.remove(paramAnonymousCallsBean);
            }
          });
          localTextView1.setText(paramAnonymousCallsBean.getCtime().split(" ")[0]);
          localTextView2.setText(paramAnonymousCallsBean.getCtime().split(" ")[1].split(":")[0] + ":" + paramAnonymousCallsBean.getCtime().split(" ")[1].split(":")[1]);
          String str1 = paramAnonymousCallsBean.getCduration();
          i = paramAnonymousCallsBean.getCtype();
          str2 = String.valueOf(Long.valueOf(str1).longValue() / 60L + "分" + Long.valueOf(str1).longValue() % 60L + "秒");
          if (i != 1)
            break label343;
          localTextView3.setText(FindCallRecord.this.getResources().getString(2131428123) + str2);
        }
        while (true)
        {
          localTextView3.setTextColor(FindCallRecord.this.getResources().getColor(2131230724));
          return paramAnonymousView;
          localCheckBox.setVisibility(8);
          break;
          label334: localCheckBox.setChecked(false);
          break label103;
          label343: if (i == 2)
            localTextView3.setText(FindCallRecord.this.getResources().getString(2131428124) + str2);
          else if (i == 3)
            localTextView3.setText(FindCallRecord.this.getResources().getString(2131428125) + str2);
          else
            localTextView3.setText(FindCallRecord.this.getResources().getString(2131428126) + str2);
        }
      }
    });
    this.lvList.setAdapter(this.adapter);
    this.lvList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
    {
      public boolean onItemLongClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        if (FindCallRecord.this.flag == 0)
        {
          FindCallRecord.this.delete_calls = ((CallsBean)FindCallRecord.this.page.getEntries().get(paramAnonymousInt));
          FindCallRecord.this.delete_calls_info = "将删除当前所选的记录";
          FindCallRecord.this.DeleteRecordDialog(FindCallRecord.this, FindCallRecord.this.delete_calls_info);
        }
        return false;
      }
    });
    this.lvList.setOnScrollListener(new AbsListView.OnScrollListener()
    {
      public void onScroll(AbsListView paramAnonymousAbsListView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
      {
      }

      public void onScrollStateChanged(AbsListView paramAnonymousAbsListView, int paramAnonymousInt)
      {
        if ((paramAnonymousInt == 0) && (paramAnonymousAbsListView.getLastVisiblePosition() == -1 + paramAnonymousAbsListView.getCount()) && (!FindCallRecord.this.lvList.getIsNoMore()) && (FindCallRecord.this.blDataTask))
        {
          FindCallRecord.this.lvList.prepareForRefreshMore();
          FindCallRecord.this.isFoot = true;
          FindCallRecord.this.loadingData(false);
        }
      }
    });
    this.lvList.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        FindCallRecord.this.lvList.prepareForRefreshMore();
        FindCallRecord.this.isFoot = true;
        FindCallRecord.this.loadingData(true);
      }
    });
    addOperation(new DataTask().execute(new String[] { "calls" }));
  }

  private void loadingData(boolean paramBoolean)
  {
    if (paramBoolean)
      this.page.firstPage();
    while (true)
    {
      addOperation(new DataTask().execute(new String[] { "calls" }));
      return;
      this.page.nextPage();
    }
  }

  private void removeCall()
  {
    for (int i = 0; ; i++)
    {
      if (i >= this.page.getEntries().size())
        return;
      this.newlist.remove(this.page.getEntries().get(i));
      this.maplist.remove(String.valueOf(((CallsBean)this.page.getEntries().get(i)).getId()));
    }
  }

  private void setEvent(int paramInt)
  {
    if (this.page.getEntries().size() > 0);
    for (int i = 0; ; i++)
    {
      if (i >= this.page.getEntries().size())
      {
        this.adapter.notifyDataSetChanged();
        return;
      }
      ((CallsBean)this.page.getEntries().get(i)).setCid(paramInt);
    }
  }

  protected void DeleteRecordDialog(Context paramContext, String paramString)
  {
    View localView = getLayoutInflater().inflate(2130903083, null);
    final Dialog localDialog = new Dialog(paramContext, 2131361814);
    localDialog.setContentView(localView);
    ((TextView)localView.findViewById(2131492904)).setText(paramString);
    TextView localTextView1 = (TextView)localView.findViewById(2131493071);
    TextView localTextView2 = (TextView)localView.findViewById(2131493070);
    localTextView1.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        localDialog.dismiss();
      }
    });
    localTextView2.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        try
        {
          if (localDialog.isShowing())
            localDialog.dismiss();
          if (FindCallRecord.this.flag == 0)
          {
            FindCallRecord.this.maplist.put(FindCallRecord.this.delete_calls.getId(), Integer.valueOf(FindCallRecord.this.delete_calls.getId()));
            FindCallRecord.this.newlist.add(FindCallRecord.this.delete_calls);
            new FindCallRecord.DataTask(FindCallRecord.this).execute(new String[] { "delcalls" });
            return;
          }
          new FindCallRecord.DataTask(FindCallRecord.this).execute(new String[] { "delcalls" });
          return;
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
        }
      }
    });
    localDialog.show();
  }

  protected void backKeyCallBack()
  {
    finish();
  }

  protected void initPopuptWindow(View paramView)
  {
    try
    {
      this.screenWidth = getWindowManager().getDefaultDisplay().getWidth();
      this.screenHeight = getWindowManager().getDefaultDisplay().getHeight();
      this.popupWindow_view = ((ViewGroup)getLayoutInflater().inflate(2130903170, null, true));
      if (this.flag == 0)
      {
        this.popupWindow = new PopupWindow(this.popupWindow_view, 2 * this.screenWidth / 5, 2 * this.screenHeight / 7, true);
        this.dialgoWidth = (this.popupWindow.getWidth() / 5);
        this.dialgoheight = this.popupWindow.getHeight();
        this.popupWindow.setBackgroundDrawable(getResources().getDrawable(2130837504));
        this.popupWindow.getBackground().setAlpha(0);
        this.popupWindow.showAsDropDown(paramView, (this.screenWidth - this.dialgoWidth) / 2, 0);
        this.list = ((ListView)this.popupWindow_view.findViewById(2131493350));
        ArrayList localArrayList2 = new ArrayList();
        HashMap localHashMap3 = new HashMap();
        localHashMap3.put("menuName", "删除");
        HashMap localHashMap4 = new HashMap();
        localHashMap4.put("menuName", "搜索记录");
        HashMap localHashMap5 = new HashMap();
        localHashMap5.put("menuName", "更多设置");
        localArrayList2.add(localHashMap3);
        localArrayList2.add(localHashMap4);
        localArrayList2.add(localHashMap5);
        SimpleAdapter localSimpleAdapter2 = new SimpleAdapter(this, localArrayList2, 2130903191, new String[] { "menuName" }, new int[] { 2131493503 });
        this.list.setAdapter(localSimpleAdapter2);
        this.list.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
          private static final String TAG = "FindRecord";

          public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
          {
            Log.v("FindRecord", paramAnonymousInt + "被点击了");
            if (paramAnonymousInt == 0)
            {
              FindCallRecord.this.popupWindow.dismiss();
              FindCallRecord.this.flag = 1;
              FindCallRecord.this.rl.setVisibility(0);
              FindCallRecord.this.adapter.notifyDataSetChanged();
            }
            if (paramAnonymousInt == 1)
            {
              FindCallRecord.this.popupWindow.dismiss();
              Intent localIntent2 = new Intent();
              localIntent2.setClass(FindCallRecord.this, CallRecordSearch.class);
              FindCallRecord.this.startActivity(localIntent2);
            }
            if (paramAnonymousInt == 2)
            {
              FindCallRecord.this.popupWindow.dismiss();
              Intent localIntent1 = new Intent();
              localIntent1.setClass(FindCallRecord.this, MoreSetActivity.class);
              FindCallRecord.this.startActivity(localIntent1);
            }
          }
        });
        return;
      }
      if (this.flag == 1)
      {
        this.popupWindows = new PopupWindow(this.popupWindow_view, 2 * this.screenWidth / 5, 2 * this.screenHeight / 8, true);
        this.dialgoWidth = (this.popupWindows.getWidth() / 5);
        this.dialgoheight = this.popupWindows.getHeight();
        this.popupWindows.setBackgroundDrawable(getResources().getDrawable(2130837504));
        this.popupWindows.getBackground().setAlpha(0);
        this.popupWindows.showAsDropDown(paramView, (this.screenWidth - this.dialgoWidth) / 2, 0);
        this.list = ((ListView)this.popupWindow_view.findViewById(2131493350));
        ArrayList localArrayList1 = new ArrayList();
        HashMap localHashMap1 = new HashMap();
        localHashMap1.put("menuName", "全选");
        HashMap localHashMap2 = new HashMap();
        localHashMap2.put("menuName", "取消全部");
        localArrayList1.add(localHashMap1);
        localArrayList1.add(localHashMap2);
        SimpleAdapter localSimpleAdapter1 = new SimpleAdapter(this, localArrayList1, 2130903191, new String[] { "menuName" }, new int[] { 2131493503 });
        this.list.setAdapter(localSimpleAdapter1);
        this.list.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
          public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
          {
            if (paramAnonymousInt == 0)
            {
              FindCallRecord.this.popupWindows.dismiss();
              FindCallRecord.this.setEvent(1);
              FindCallRecord.this.addCall();
            }
            if (paramAnonymousInt == 1)
            {
              FindCallRecord.this.setEvent(0);
              FindCallRecord.this.popupWindows.dismiss();
              FindCallRecord.this.removeCall();
            }
          }
        });
        return;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void onBackPressed()
  {
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903081);
    initActionBar();
    Intent localIntent = getIntent();
    this.per_num = localIntent.getStringExtra("NUM");
    this.TIMES = localIntent.getStringExtra("TIMES");
    this.times = Integer.valueOf(this.TIMES);
    initView();
  }

  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    switch (paramInt)
    {
    default:
    case 4:
    }
    do
      return super.onKeyDown(paramInt, paramKeyEvent);
    while ((this.popupWindow == null) || (!this.popupWindow.isShowing()));
    this.popupWindow.dismiss();
    this.popupWindow = null;
    return true;
  }

  protected void onResume()
  {
    super.onResume();
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    String param;

    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.param = paramArrayOfString[0];
      RqSP localRqSP = new RqSP();
      String str1 = localRqSP.getLgDevAccount(FindCallRecord.this);
      String str2 = localRqSP.getLgDevId(FindCallRecord.this);
      try
      {
        if (this.param.equals("calls"))
        {
          FindCallRecord.this.events = new SearchRecordService().getCallsList(str1, str2, FindCallRecord.this.per_num, null, FindCallRecord.this.page.getPageNo(), FindCallRecord.this.page.getPageSize(), FindCallRecord.this);
        }
        else if (this.param.equals("delcalls"))
        {
          FindCallRecord.this.bean = new SearchRecordService().delRecordList(str1, str2, FindCallRecord.this.maplist, "DLCallRecord", FindCallRecord.this);
          String str3 = FindCallRecord.this.bean.getDesc();
          return str3;
        }
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
      }
      catch (XmlPullParserException localXmlPullParserException)
      {
        localXmlPullParserException.printStackTrace();
      }
      catch (TimeOutException localTimeOutException)
      {
        localTimeOutException.printStackTrace();
      }
      catch (NotFoundNetWorkException localNotFoundNetWorkException)
      {
        localNotFoundNetWorkException.printStackTrace();
      }
      return null;
    }

    protected void onPostExecute(String paramString)
    {
      if (this.param.equals("calls"))
        if ((FindCallRecord.this.events != null) && (FindCallRecord.this.events.size() > 0))
        {
          FindCallRecord.this.page.addAllEntries(FindCallRecord.this.events);
          FindCallRecord.this.adapter.notifyDataSetChanged();
          FindCallRecord.this.lvList.onLoadMoreComplete();
          if (FindCallRecord.this.events.size() < FindCallRecord.this.page.getPageSize())
          {
            FindCallRecord.this.lvList.hideFotterMoreView();
            FindCallRecord.this.lvList.setIsNoMore(true);
          }
          FindCallRecord.this.events.clear();
          FindCallRecord.this.blDataTask = true;
        }
      while (true)
      {
        if (!FindCallRecord.this.isFoot)
        {
          FindCallRecord.this.closeProgress();
          FindCallRecord.this.isFoot = false;
        }
        super.onPostExecute(paramString);
        return;
        FindCallRecord.this.lvList.hideFotterMoreView();
        FindCallRecord.this.lvList.setIsNoMore(true);
        break;
        if (this.param.equals("delcalls"))
        {
          if ("0".equals(FindCallRecord.this.bean.getCode()))
          {
            FindCallRecord.this.page.getEntries().removeAll(FindCallRecord.this.newlist);
            if (FindCallRecord.this.times.intValue() > FindCallRecord.this.newlist.size())
            {
              FindCallRecord localFindCallRecord = FindCallRecord.this;
              localFindCallRecord.times = Integer.valueOf(localFindCallRecord.times.intValue() - FindCallRecord.this.newlist.size());
              Log.v("FindCallRecord", "page.getEntries().size() : " + FindCallRecord.this.times);
              FindRecord.CallsASI.setCtimes(String.valueOf(FindCallRecord.this.times));
            }
            while (true)
            {
              FindCallRecord.this.maplist.clear();
              FindCallRecord.this.newlist.clear();
              FindCallRecord.this.adapter.notifyDataSetChanged();
              FindCallRecord.this.alertMessage(FindCallRecord.this.getResources().getString(2131427527));
              break;
              if (FindCallRecord.this.times.intValue() == FindCallRecord.this.newlist.size())
                FindRecord.CallsASI.setCtimes("0");
            }
          }
          FindCallRecord.this.alertMessage(FindCallRecord.this.getResources().getString(2131427528));
        }
      }
    }

    protected void onPreExecute()
    {
      FindCallRecord.this.blDataTask = false;
      if (!FindCallRecord.this.isFoot)
        FindCallRecord.this.showProgress("");
      super.onPreExecute();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.FindCallRecord
 * JD-Core Version:    0.6.2
 */